/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Mrhung
 */
public class HangHoa {
    private String Mahang;
    private String Tenhang;
    private String Chungloai;
    private float  Dongia;
    private String Donvitinh;
    private String HSD;
    private int Soluong;
    
    private DBHelper conn = new DBHelper();

    /**
     * @return the Mahang
     */
    public String getMahang() {
        return Mahang;
    }

    /**
     * @param Mahang the Mahang to set
     */
    public void setMahang(String Mahang) {
        this.Mahang = Mahang;
    }

    /**
     * @return the Tenhang
     */
    public String getTenhang() {
        return Tenhang;
    }

    /**
     * @param Tenhang the Tenhang to set
     */
    public void setTenhang(String Tenhang) {
        this.Tenhang = Tenhang;
    }

    /**
     * @return the Chungloai
     */
    public String getChungloai() {
        return Chungloai;
    }

    /**
     * @param Chungloai the Chungloai to set
     */
    public void setChungloai(String Chungloai) {
        this.Chungloai = Chungloai;
    }

    /**
     * @return the Dongia
     */
    
    /**
     * @param Dongia the Dongia to set
     */
   
    /**
     * @return the Donvitinh
     */
    public String getDonvitinh() {
        return Donvitinh;
    }

    /**
     * @param Donvitinh the Donvitinh to set
     */
    public void setDonvitinh(String Donvitinh) {
        this.Donvitinh = Donvitinh;
    }

    /**
     * @return the Soluong
     */
    public int getSoluong() {
        return Soluong;
    }
     public String getHSD() {
        return HSD;
    }

    /**
     * @param HSD the HSD to set
     */
    public void setHSD(String HSD) {
        this.HSD = HSD;
    }
      public float getDongia() {
        return Dongia;
    }

    /**
     * @param Dongia the Dongia to set
     */
    public void setDongia(float Dongia) {
        this.Dongia = Dongia;
    }
    /**
     * @param Soluong the Soluong to set
     */
    public void setSoluong(int Soluong) {
        this.Soluong = Soluong;
    }
     public HangHoa(){}
    public HangHoa(String Mahang, String Tenhang, String Chungloai, float Dongia, String Donvitinh,String HSD,int Soluong){
        this.setMahang(Mahang);
        this.setTenhang(Tenhang);
        this.setChungloai(Chungloai);
        this.setDongia(Dongia);
        this.setDonvitinh(Donvitinh);
        this.setHSD(HSD);
        this.setSoluong(Soluong);
    }
     public int insertHangHoa(HangHoa a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMahang());
            v.add(a.getTenhang());
            v.add(a.getChungloai());
            v.add(a.getDongia());
            v.add(a.getDonvitinh());
            v.add(a.getHSD());
            v.add(a.getSoluong());
            i=conn.executeUpdate("sp_InsertHangHoa",v);
        }catch(SQLException ex){}
        return i;
    }
      public int DelHangHoa(String MaHang) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(MaHang);           
            i=conn.executeUpdate("sp_DellHangHoa",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public Vector getAllHangHoa() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("sp_getAllHangHoa");
            while(rs.next())
            {                  
                HangHoa b = new HangHoa();
                b.setMahang(rs.getString(1));
                b.setTenhang(rs.getString(2));
                b.setChungloai(rs.getString(3));
                b.setDongia(rs.getFloat(4));
                b.setDonvitinh(rs.getString(5));
                b.setHSD(rs.getString(6));
                b.setSoluong(rs.getInt(7));
                
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
    public int updateHangHoa(HangHoa a) throws SQLException
    {
        DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMahang());
            v.add(a.getTenhang());
            v.add(a.getChungloai());
            v.add(a.getDongia());
            v.add(a.getDonvitinh());
            v.add(a.getHSD());
            v.add(a.getSoluong());
            i=obj.executeUpdate("sp_updateHangHoa",v);
        }catch(SQLException ex){}
        return i;
    }
    public Vector getHangHoa_MaHang(String Mahang) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(Mahang);
        try{
            ResultSet rs = conn.executeQuery("sp_getMaHang", v1);
            while(rs.next()){
                HangHoa b = new HangHoa();
                b.setMahang(rs.getString(1));
                b.setTenhang(rs.getString(2));
                b.setChungloai(rs.getString(3));
                b.setDongia(rs.getFloat(4));
                b.setDonvitinh(rs.getString(5));
                b.setHSD(rs.getString(6));
                b.setSoluong(rs.getInt(7));
                
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v; 
    }
    
    public Vector getHangHoa_TenHang(String Tenhang) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(Tenhang);
        try{
            ResultSet rs = conn.executeQuery("sp_getTenhang", v1);
            while(rs.next()){
                HangHoa b = new HangHoa();
                b.setMahang(rs.getString(1));
                b.setTenhang(rs.getString(2));
                b.setChungloai(rs.getString(3));
                b.setDongia(rs.getFloat(4));
                b.setDonvitinh(rs.getString(5));
                b.setHSD(rs.getString(6));
                b.setSoluong(rs.getInt(7));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }
    
 public Vector getHangHoa_Chungloai(String Chungloai) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(Chungloai);
        try{
            ResultSet rs = conn.executeQuery("sp_getChungloai1", v1);
            while(rs.next()){
                HangHoa b = new HangHoa();
                b.setMahang(rs.getString(1));
                b.setTenhang(rs.getString(2));
                b.setChungloai(rs.getString(3));
                b.setDongia(rs.getFloat(4));
                //b.setDongia(rs.getString(4));
                b.setDonvitinh(rs.getString(5));
                b.setHSD(rs.getString(6));
                b.setSoluong(rs.getInt(7));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }

    /**
     * @return the Dongia
     */
  

    /**
     * @param Dongia the Dongia to set
     */
   
    /**
     * @return the HSD
     */
   

    /**
     * @return the conn
     */
    
    
}
